/**
 *  This code is a part of Quadratix project.
 * Copyright (C) 2009 - 2010 Valery A. Ilychev aka Sarutobi (ilychev at gmail dot com)
 * 
 *  This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
package ru.sarutobi.quadratix.ui;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import ru.sarutobi.quadratix.Board;

public class NamePanel extends JPanel {
	private int wScore;
	private int bScore;
	
	private JTextField move = new JTextField();
	
	private JLabel wScoreLabel = new JLabel();
	private JLabel bScoreLabel = new JLabel();
	
	public NamePanel() {
		setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
		Box top = Box.createVerticalBox();
		//setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		top.add(new JLabel("White"));
		top.add(new JTextField("White"));
		top.add(new JLabel("Score"));
		top.add(wScoreLabel);
		top.add(new JLabel("Black"));
		top.add(new JTextField("Black"));
		top.add(new JLabel("Score"));
		top.add(bScoreLabel);
		top.add(move);
		//add (Box.createVerticalGlue());
		move.setText("White move");
		wScoreLabel.setText("0");
		bScoreLabel.setText("0");
		add(top);
	}
	
	public void setMove(int move){
		String text = (move == Board.WHITE) ? "White move" : "Black move";
		this.move.setText(text);
	}
	
	public void addWhiteScore(int score){
		wScore += score;
		wScoreLabel.setText(String.format("%d", wScore));
	}

	public void addBlackScore(int score){
		bScore += score;
		bScoreLabel.setText(String.format("%d", bScore));
	}

	public void resetScore() {
		bScore = 0;
		wScore = 0;
		bScoreLabel.setText("0");
		wScoreLabel.setText("0");
	}
	
	
	public void showWinner(){
		String winner = (wScore > bScore) ? "White" : "Black";
		move.setText(String.format("%s wins!", winner));
	}
	
}
